/**
 * 
 */
package game.kill.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import game.kill.mapper.RoomMapper;
import game.kill.model.Room;
import game.kill.service.RoomService;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;

/**
 * @author leiruiqi
 *
 */

@Service("roomService")
public class RoomServiceImpl implements RoomService {

	@Resource
	private RoomMapper roomMapper;
	
	@Override
	public void save(Room room) {
		roomMapper.insert(room);
	}

	@Override
	public List<Room> queryByMasterId(Long userId) {
		Room room = new Room();
		room.setMasterId(userId);
		return roomMapper.select(room);
	}

	@Override
	public Room getById(Long id) {
		return roomMapper.selectByPrimaryKey(id);
	}

	@Override
	public boolean updateRoundStep(Room room) {
		
		Example condition = new Example(Room.class);
		condition.createCriteria().andEqualTo("id", room.getId());
		Room updateRoom = new Room();
		updateRoom.setStep(room.getStep());
		updateRoom.setRound(room.getRound());
		return 1== roomMapper.updateByExampleSelective(updateRoom, condition);
	}

	@Override
	public boolean updateStatus(Room room) {
		Example condition = new Example(Room.class);
		condition.createCriteria().andEqualTo("id", room.getId());
		Room updateRoom = new Room();
		
		updateRoom.setStatus(room.getStatus());
		return 1== roomMapper.updateByExampleSelective(updateRoom, condition);
	}

	@Override
	public List<Room> findAllRoomByStatus(Integer status) {
		Example condition = new Example(Room.class);
		condition.createCriteria().andEqualTo("status", status);
		
		return roomMapper.selectByExample(condition);
		
	}

}
